const express = require("express");
const logger = require("morgan");
const router = require("./routers/indexRouter") //引入router模块
const bodyParser = require("body-parser")
const favicon = require("serve-favicon")


const myapp = express(); //启动服务
//设置允许跨域访问该服务.
myapp.all('*', function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    // res.header('Access-Control-Allow-Headers', 'Content-Type');
    res.header('Access-Control-Allow-Methods', '*');
    // res.header('Content-Type', 'application/json;charset=utf-8');
    next();
  });
myapp.use(logger("dev")) //配置日志
myapp.use(bodyParser.urlencoded({extended:false})) // 配置post解析
myapp.use(bodyParser.json()) // 转换数据格式
myapp.use(express.static(__dirname + "/src")) //配置静态资源路径
myapp.use(favicon(__dirname + "/src/image/favicon.png"))

myapp.use(router) //使用router模块拦截请求（分层）


myapp.listen(5678, () => { //端口
    console.log("express服务器启动")
})
  